<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:s="http://jboss.com/products/seam/taglib"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:a4j="http://richfaces.org/a4j">
	
	<a4j:form id="saleQueryForm" styleClass="trn_form">
		
		<a4j:outputPanel id="msgContainer" ajaxRendered="true">
				<h:messages globalOnly="false" errorClass="msgError" styleClass="message" infoClass="msgInfo" />
			</a4j:outputPanel>
		<a4j:outputPanel id="saleQueryHeadPanel">
			<div id="Form_Table">
				<div id="Form_Row">
					<div class="form_fields">
						<s:label for="saleQueryCustomer">Cliente:</s:label>
						<h:selectOneMenu 
							styleClass="input"
							converter="#{customerConverter}"
							value="#{trnSale.saleQueryHead.customerData}"
							id="saleQueryCustomer" >
							<a4j:support event="onchange" />
							<s:selectItems 
								value="#{withinHolder.customerList()}" 
								var="cust"
								label="#{convertAssist.getCustomerName(cust.id)}"
								noSelectionLabel="Cliente">
							</s:selectItems>
						</h:selectOneMenu>
						<div id="saleQueryCustomerMsg" class="inactiveMsg"></div>
					</div>
					<div class="form_fields">
						<s:label for="saleQueryStatus">Estado:</s:label>
						<h:selectOneMenu
							styleClass="input"
							value="#{trnSale.saleQueryHead.status}"
							id="saleQueryStatus" >
							<a4j:support event="onchange" />
							<f:selectItem itemValue=""/>
							<f:selectItem itemLabel="PENDIENTE" itemValue="PEND" />
							<f:selectItem itemLabel="CONFIRMADO" itemValue="CONF"/>
							<f:selectItem itemLabel="ANULADO" itemValue="ANUL"/>
							<a4j:support event="onblur" />
						</h:selectOneMenu>
						<div id="saleQueryStatusMsg" class="inactiveMsg"></div>
					</div>
					<div class="form_fields">
						<s:label for="saleQueryVoucherDate">Fecha Comprobante:</s:label>
						<rich:calendar
							inputClass="input"
							id="saleQueryVoucherDate"
							value="#{trnSale.saleQueryHead.voucherDate}" 
							datePattern="dd/MM/yy"
							buttonClass="field_btn"/>
						<a4j:commandButton
								action="#{trnSale.retrieveFilteredSales()}"
								id="saleQuerySearchBtn"
								value="Buscar" 
								reRender="saleQueryForm, saleQueryHeadGridPanel"
								styleClass="button"
								style="position:relative; left:10px; padding-bottom:4px; bottom:7px;"
								/>
						<div id="saleQueryVoucherDateMsg" class="inactiveMsg"></div>
					</div>
				</div>
			</div>				
		</a4j:outputPanel>
		<a4j:outputPanel id="saleQueryHeadGridPanel">	
				<rich:datascroller align="center" for="saleQueryHeadGrid"
						maxPages="15" page="#{trnSale.scrollerPage}"
						renderIfSinglePage="false" />			   			
				<div style="clear: both;" />
				<rich:panel styleClass="table_add" rendered="#{not empty trnSale.allSalesQueryHead}">
					<rich:dataTable id="saleQueryHeadGrid"
						var="saleHead" rows="10"
						value="#{trnSale.allSalesQueryHead}}"
						rendered="#{not empty trnSale.allSalesQueryHead}}"
						rowClasses="rvgRowOne,rvgRowTwo"
						style="align:center;">
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Proveedor" /></f:facet>
							<h:outputText value="#{convertAssist.getCustomerName(saleHead.idCustomer)}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Nro. Factura" /></f:facet>
							<h:outputText value="#{saleHead.voucher}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Fecha. Comprobante" /></f:facet>
							<h:outputText value="#{saleHead.voucherDate}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Tipo Venta" /></f:facet>
							<h:outputText value="#{convertAssist.getRefDetDescrip(saleHead.saleType)}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Moneda" /></f:facet>
							<h:outputText value="#{convertAssist.getCurrencyDescById(saleHead.currency)}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Total Factura" /></f:facet>
							<h:outputText value="#{saleHead.total}" />
						</rich:column>
						<rich:column>
							<f:facet name="header"><h:outputText value="Estado" /></f:facet>
							<h:outputText value="#{saleHead.status}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Detalle" /></f:facet>
							<a4j:commandLink id="viewOrderQueryDet"  
							    action="#{trnSale.retriveSalesDet(saleHead.id, 'QUERY')}"
								oncomplete="#{rich:component('modalSaleQueryDet')}.show()"
								reRender="modalSaleQueryDet"
								immediate="true">
	
								<h:graphicImage id="viewOrderQueryDetEditImg" url="/img/icons/database_table.png"
									styleClass="actionsImages" />
							</a4j:commandLink>
							<rich:toolTip value="Ver Detalle" for="viewDet" />
						</rich:column>
		
					</rich:dataTable>
				</rich:panel>
			</a4j:outputPanel>
			<a4j:commandLink
					id="saleQueryCloseBtn"
					styleClass="button"
					onclick="#{rich:component('SaleQueryCloseModalPanel')}.show()" 
					style="position:relative; float:right; right:15px; margin-top:15px;">
					<h:graphicImage value="/img/icons/close.png"/>
			</a4j:commandLink>
	</a4j:form>
	
	<rich:modalPanel  id="SaleQueryCloseModalPanel"
			resizeable="false" autosized="true" moveable="false" style="bsale:2px solid #6FADDF">
			<a4j:form>
			<div class="globalMessage">
				<h:outputText value="Esta seguro que desea cancelar la operacion?" />
			</div>
			<s:decorate template="/layout/displayButton.xhtml" styleClass="trn_button_form" style="width:270px; margin-top:0px; margin-left:auto;">
				<a4j:commandButton
					action="#{trnSale.cleanQuery()}"
					value="Aceptar" 
					id="SaleQueryAcceptClose"
					reRender="saleQueryForm"
					oncomplete="#{rich:component('SaleQueryCloseModalPanel')}.hide();#{rich:component('modalSaleQuery')}.hide();"
					styleClass="button" />
				<rich:spacer width="20px" />
				<a4j:commandButton value="Cancelar" id="SaleQueryCancelClose"
					onclick="#{rich:component('SaleQueryCloseModalPanel')}.hide()"
					styleClass="button" />
			</s:decorate>
			</a4j:form>
		</rich:modalPanel>
	
	<rich:modalPanel  id="modalSaleQueryDet"  minwidth="800" minheight="400" 
		resizeable="false" autosized="true" top="30">
		<f:facet name="header">
			<h:panelGroup>
				<h:outputText value="Detalle de la Venta" />
				</h:panelGroup>
		</f:facet>
		<f:facet name="controls">
			<h:panelGroup>
				<h:graphicImage value="/img/close.png" style="cursor:pointer"
					id="modalSaleQueryDetHide" />
				<rich:componentControl for="modalSaleQueryDet"
					attachTo="modalSaleQueryDetHide" operation="hide" event="onclick" />
			</h:panelGroup>
		</f:facet>
			<rich:panel styleClass="table_add" rendered="#{not empty trnSale.allSalesQueryDet}">
				<rich:dataTable id="saleQueryDetGrid"
						var="saleDet" rows="10"
						value="#{trnSale.allSalesQueryDet}"
						rendered="#{not empty trnSale.allSalesQueryDet}"
						rowClasses="rvgRowOne,rvgRowTwo"
						style="align:center;">

						<rich:column>
							<f:facet name="header"><h:outputText value="Item" /></f:facet>
							<h:outputText value="#{saleDet.item}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Producto" /></f:facet>
							<h:outputText value="#{convertAssist.getSupplyDesc(saleDet.saleProduct)}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Cantidad" /></f:facet>
							<h:outputText value="#{saleDet.quantity}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Precio" /></f:facet>
							<h:outputText value="#{saleDet.basicPrice}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Descuento" /></f:facet>
							<h:outputText value="#{saleDet.discount}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Recargo" /></f:facet>
							<h:outputText value="#{saleDet.charge}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="IVA" /></f:facet>
							<h:outputText value="#{convertAssist.getTaxDesc(saleDet.tax)}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Gravadas" /></f:facet>
							<h:outputText value="#{saleDet.taxedAmount}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Exentas" /></f:facet>
							<h:outputText value="#{saleDet.exemptAmount}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Total" /></f:facet>
							<h:outputText value="#{saleDet.itemAmount}" />
						</rich:column>
		
					</rich:dataTable>
			</rich:panel>
	</rich:modalPanel>
	
</ui:composition>